const TABLE_COLUMNS = [
  { title: '开票供应商代码', field: 'invoiceSupplierCode', width: 150, slots: { default: 'supplierCode' } },
  { title: '开票供应商', field: 'invoiceSupplierName', width: 300, slots: { default: 'supplier' } },
  { title: '收款人', field: 'payee', minWidth: 200, editRender: { placeholder: '请点击输入...' }, slots: { edit: 'payee_edit' } },
  { title: '收款账号', field: 'bankAccount', minWidth: 200, editRender: { placeholder: '请点击输入...' }, slots: { edit: 'bank_account_edit' } },
  { title: '开户行', field: 'bank', minWidth: 200, editRender: { placeholder: '请点击输入...' }, slots: { edit: 'bank_edit' } },
  { title: '联行号', field: 'bankNumber', minWidth: 200 },
  { title: '是否承兑', field: 'acceptInvoice', defaultValue: 2, width: 150, editRender: {}, slots: { edit: 'accept_invoice_edit', default: 'accept_invoice_default' } },
  { title: '排列顺序', field: 'sort', minWidth: 200, editRender: { placeholder: '请点击输入...' }, slots: { edit: 'sort_edit' } },
  { title: '停用收款信息', field: 'deactivate', defaultValue: 2, width: 150, editRender: {}, slots: { edit: 'deactivate_edit', default: 'deactivate_default' } },
  { title: '解除关系', field: 'unfriend', defaultValue: 2, width: 150, editRender: {}, slots: { edit: 'unfriend_edit', default: 'unfriend_default' } },
  { title: '与供应商关系', field: 'relation', width: 200, editRender: {}, slots: { edit: 'relation_edit', default: 'relation_default' } },
  { title: '不一致原因', field: 'differentReason', width: 200, editRender: {}, slots: { edit: 'reason_edit', default: 'reason_default' } },
  { title: '不一致原因说明', field: 'differentRemark', width: 300, editRender: { placeholder: '请点击输入...' }, slots: { edit: 'remark_edit' } },
  { title: '关系证明', field: 'relationAnnex', slots: { default: 'annex' }, width: 120, },
  { title: '操作', slots: { default: 'actions' }, width: 80, },
]
const getTableColumns = (readonly) => {
  if (readonly) {
    const list = TABLE_COLUMNS.map((item) => {
      const obj = Object.create(null)
      for (let [key, value] of Object.entries(item)) {
        if (key === 'slots' && value.default) {
          obj[key] = { default: value.default }
        } else if (key != 'editRender') {
          obj[key] = value
        }
      }
      return obj
    })
    list.pop()
    return list
  }
  return TABLE_COLUMNS
}
const getInitialFieldsValue = (readonly) => {
  const getColField = (list) => {
    const obj = {}
    list.forEach(({ field, defaultValue = '' }) => {
      obj[field] = defaultValue
    });
    obj['invoiceSupplierId'] = ''
    obj['bankBranchId'] = ''
    return obj
  }
  return getColField(getTableColumns(readonly))
}
export default { getInitialFieldsValue, getTableColumns, }
